<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>交款流水审核</title>
<%@include file="/jsp/common/inc.jsp"%>
<script type="text/javascript">
	var grid;// 交款流水信息
	$(function() {
		grid = $("#grid").datagrid({
			url : "${pageContext.request.contextPath}/jklsAuditController/datagrid",
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			fitColumns : true,
			idField : "id",
			pagesize : 10,
			pageList : [10,20,30],
			toolbar : "#toolbar",
			columns : [ [ {
				width : 100,
				title : "分店",
				field : "branch",
				formatter : function(value,rowData,rowIndex){
					return value.branchName;
				}
			},{
				width : 100,
				title : "交款人姓名",
				field : "xm"
			},{
				width : 100,
				title : "交款流水号",
				field : "jklsh"
			},{
				width : 100,
				title : "开始时间",
				field : "startDate"
			},{
				width : 100,
				title : "结束时间",
				field : "endDate"
			},{
				width : 100,
				title : "交款时间",
				field : "jksj"
			},{
				width : 100,
				title : "应交现金",
				field : "yjxj"
			},{
				width : 100,
				title : "实交现金",
				field : "sjxj"
			},{
				width : 100,
				title : "审核状态",
				field : "auditStatus",
				formatter : function(value, rowDate, rowIndex){
					if("N" == value){
						return "未审核";
					}else{
						return "已审核";
					}
				}
			},{
				width : 100,
				title : "操作",
				field : "action",
				formatter : function(value,rowData,rowIndex) {
					var str = "";
					if("N" == rowData.auditStatus){
						str +=  "<button onclick='auditFun(" + rowIndex + ")'>审核通过</buttion>";
						str +=  "<button onclick='editFun(" + rowIndex + ")'>编辑</buttion>";
					}
					return str;
				}
			} ] ]

		});
	});
	function searchFun(){
		grid.datagrid("load",sy.serializeObject($("#_form")));
	}
	// 直接审核通过
	function auditFun(rowIndex){
		var id = grid.datagrid("getRows")[rowIndex].id;
		var url = "${pageContext.request.contextPath}/jklsAuditController/auditpass/" + id;
		parent.$.messager.confirm("询问","确认审核通过?",function(r){
			if(r){
				$.post(url,null,function(result){
					parent.$.messager.alert("提示",result.msg,"info");
					grid.datagrid("reload");
				},"json");
			}
		})
	};
	
	// 分店列表
	$(function(){
		$("#fdId").combobox({
			url : "${pageContext.request.contextPath}/commonController/branchList",
			valueField : 'id',
			textField : 'branchName',
			width : 100,
		});
	});

	//编辑
	var editFun = function(rowIndex){
		var row = grid.datagrid("getRows")[rowIndex];
		$('#dlg').dialog('open').dialog('setTitle','编辑');
        $("#editForm").form("load",row);
	};
	
	// 清空查询条件
	function clearFun(){
		$("#_form").find("input").val("");
		grid.datagrid("load",{});
	}
	// 保存
	function saveFun(){
		$('#editForm').form('submit',{
             url: "${pageContext.request.contextPath}/jklsAuditController/updateJkls",
             success: function(result){
            	 var res = $.parseJSON(result);
                 if(res.success){
                	 $('#dlg').dialog('close');   
                     grid.datagrid('load');
                     $.messager.alert("提示:","操作成功","info");
                 }else{
                	 $.messager.alert("提示",res.msg,"error");
                 }
             }
         });
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	
	<div id="toolbar" style="display: none;">
		<form id="_form">
			<table>
				<tr>
					<td>分店</td>
					<td>
						<input id="fdId" name="fdId" />
					</td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchFun()">查询</a></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearFun()">清空</a></td>
				</tr>
			</table>
		</form>
	</div>
	
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
	
    <div id="dlg" class="easyui-dialog" style="width:560px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <form id="editForm" method="post" novalidate>
           <input name="id" id="id" type="hidden" />
           <fieldset>
			<legend>交款流水</legend>
			<table style="width: 100%">
				<tr>
					<td>应交现金</td>
					<td><input name="yjxj" id="yjxj" class="easyui-textbox easyui-numberbox" 
					       readonly="true" data-options="precision:2"/></td>
					<td>实交现金</td>
					<td><input name="sjxj" id="xjsj" class="easyui-textbox easyui-numberbox" maxlength="12"
					      data-options="precision:2" /></td>
				</tr>
			</table>
		</fieldset>
        </form>
    </div>
  
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="saveFun()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
	
</body>
</html>
